/*
 *  header.h
 *  oE6
 *
 *  Created by Tony Million on 12/12/2008.
 *  Copyright 2008 HowlerTech. All rights reserved.
 *
 */

#pragma once

#define LAYER1				0
#define LAYER2				1
#define LAYER3				2

#define MPEG1				0
#define MPEG2				1
#define MPEG25				2

#define MODE_STEREO			0
#define MODE_JOINT_STEREO	1	// see MODE_EXT defines
#define MODE_DUAL_CHANNEL	2
#define MODE_MONO			3

//mode extensions
// for LAYER3
#define MODE_EXT_STEREO		0	// stream is actually MODE_STEREO
#define MODE_EXT_IS			1	// Intensity stereo coding is used
#define MODE_EXT_MS			2	// MS Stereo is used
#define MODE_EXT_ISMS		3	// both Intensity and MS stereo are used

#define EMPH_NONE			0	// no deemphasis
#define EMPH_5015			1	// 50/15 microseconds
#define EMPH_RESERVED		2	// should never happen
#define EMPH_CCITT			3	// CCITT j.17

typedef	struct _header_ {
	unsigned long	MpegVersion;
	unsigned long	Layer;

	unsigned long	SampleRateIndex;

	unsigned long	ProtectionBit;
	
	unsigned long	BitrateIndex;
	
	unsigned long	PaddingBit;
	unsigned long	PrivateBit;
	
	unsigned long	Mode;
	unsigned long	Mode_Extension;
	
	unsigned long	Copyright;
	unsigned long	Original;
	unsigned long	Emphasis;
	
	// Calculated stuff
	unsigned long	SideInfoSize;
	unsigned long	AudioDataSize;
		
	unsigned long	CRCPresent;
	unsigned short	CRC;	
	
	unsigned long	Bitrate;
	unsigned long	SampleRate;
	unsigned long	Channels;
	
} header;

int decodeHeader(unsigned char * bytes, header * head);